package com.draw.core;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity()
@Table(name = "Vector")
public class Vector implements Serializable , Comparable<Vector> {
	private static final long serialVersionUID = -4240132159521665372L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private int id;

	@ManyToOne
	@JoinColumn(name = "line", nullable = false)
	private Line line;

	@ManyToOne
	@JoinColumn(name = "source", nullable = false)
	private Point source;

	@ManyToOne
	@JoinColumn(name = "destination", nullable = false)
	private Point destination;

	public Vector() {
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Point getSource() {
		return source;
	}

	public void setSource(Point source) {
		this.source = source;
	}

	public Point getDestination() {
		return destination;
	}

	public void setDestination(Point destination) {
		this.destination = destination;
	}

	public Line getLine() {
		return line;
	}

	public void setLine(Line line) {
		this.line = line;
	}
	
	public int compareTo(Vector v) {
		if (this.getSource().getTimestamp() >= v.getDestination().getTimestamp() ) {
			return 1;
		}
		if (this.getDestination().getTimestamp() <= v.getSource().getTimestamp() ) {
			return -1;
		}
		return 0;
		
	}
}
